import serial
import time
 
arduino = serial.Serial('/dev/ttyACM0',9600) #Create Serial port object called arduino
time.sleep(1) #wait for 1 secounds for the communication to get established

str = arduino.readline()
print(str.decode("utf-8")) #read the serial data and print it as line
print("Enter 1 to turn ON LED and 0 to turn OFF LED")

while True: #Do this forever
    num = input("Enter a number (1 or 0): ") #get input from user
    
    if (num == '1'): 
        arduino.write(num.encode("utf-8"))
        print("LED turned ON")    
    elif (num == '0'): 
        arduino.write(num.encode("utf-8"))
        print("LED turned OFF")
    else:
        print('Input error. Try again.')
